import { getQueryPageApi } from "@/api/approval/approvalManagement";
import { getUserByPositionApi } from "@/api/managementCenter/departmentPersonnel";
import { getCustomerSelectList } from "@/api/managementCenter/customerManagement";

import { reactive } from "vue";

export const searchItemList: Array<SuperSearch.SearchItem> = [
  {
    type: "input",
    label: "运单号",
    keyName: "waybillNumList",
    placeholder: "支持批量(空格/逗号隔开)"
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "客户简称",
    keyName: "customerIdList",
    optionsRequest: getCustomerSelectList,
    optReqParams: { isFilterChild: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    attrs: {
      mode: "multiple"
    },
    optConfig: {
      label: "shortName",
      value: "id"
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "问题件类型",
    keyName: "problemPieceTypeList",
    optionsRequest: getQueryPageApi,
    optReqParams: { pageNum: 1, pageSize: 100 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "type",
      value: "type"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),

  {
    type: "select",
    label: "状态",
    keyName: "stateList",
    optConfig: {
      label: "name",
      value: "code"
    },
    options: [
      {
        name: "待审批",
        code: 0
      },
      {
        name: "审批中",
        code: 1
      },
      {
        name: "审批驳回",
        code: 2
      },
      {
        name: "待确认",
        code: 3
      },
      {
        name: "审批完成",
        code: 4
      },
      {
        name: "取消",
        code: 5
      }
    ],
    attrs: {
      mode: "multiple"
    }
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "发起人",
    keyName: "createByList",
    optionsRequest: getUserByPositionApi,
    optReqParams: { status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "username",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },

    options: []
  }),
  {
    type: "datetimerange",
    label: "创建时间",
    keyName: "time"
  }
];

// 列表
export const tableColumn: Array<SuperTable.TableCoulmnItem | SuperTable.NestTableColumnItem> = [
  {
    field: "waybillNum",
    title: "运单号",
    minWidth: "140"
  },
  {
    field: "problemPieceType",
    title: "问题件类型",
    minWidth: "140"
  },
  {
    field: "shortName",
    title: "客户简称",
    minWidth: "140"
  },
  {
    field: "description",
    title: "描述",
    minWidth: "120"
  },
  {
    field: "eee",
    title: "分摊金额",
    minWidth: "160",
    renderSlot: "eee"
  },
  {
    field: "progress",
    title: "进度",
    minWidth: "120"
  },
  {
    field: "state",
    title: "审批状态",
    minWidth: "120",
    renderSlot: "state"
  },
  {
    field: "createName",
    title: "发起人",
    minWidth: "120"
  },
  {
    field: "createTime",
    title: "发起时间",
    minWidth: "120",
    formatter: "formatDate"
  },
  {
    field: "action",
    title: "操作",
    minWidth: "180",
    renderSlot: "action"
  }
];
